home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
TransSkel.cpt
/
DialogSkel.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-01-07
|
7KB
|
335 lines
{ this program requires MacPasLib, MacTraps, and TransSkelPas in the same }
{ project. Puts up 2 dialog boxes, whose items affect the other dialog }
{ ported to LS Pascal by Owen Hartnett, Ωhm Software Co. }
{ 7 January 1987 }
PROGRAM DialogSkel;
USES
TransSkelPas;
CONST
mDlogRes = 1000;
aboutAlrtRes = 1001; { About... alert resource number }
showDlog1 = 1; { File Menu item numbers }
showDlog2 = 2;
quit = 4;
undo = 1; { Edit menu item numbers }
cut = 3;
copy = 4;
paste = 5;
clear = 6;
button1 = 1; { dialog item numbers }
edit1 = 2;
static1 = 3;
radio1 = 4;
radio2 = 5;
radio3 = 6;
check1 = 7;
check2 = 8;
user1 = 9;
TYPE
EventPtr = ^EventRecord;
VAR
mDlog1, mDlog2 : DialogPtr;
iconNum1, iconNum2 : integer;
PROCEDURE DrawIcon (dlog : DialogPtr;
item : integer);
VAR
h, itemHandle : Handle;
itemType : integer;
itemRect : Rect;
BEGIN
GetDItem(dlog, item, itemType, itemHandle, itemRect);
IF dlog = mDlog1 THEN
h := GetIcon(iconNum1)
ELSE
h := GetICon(iconNum2);
PlotIcon(itemRect, h);
END;
FUNCTION GetDctl (dlog : DialogPtr;
item : integer) : Boolean;
VAR
itemHandle : Handle;
itemType : integer;
itemRect : Rect;
BEGIN
GetDItem(dlog, item, itemType, itemHandle, itemRect);
GetDCtl := Boolean(GetCtlValue(ControlHandle(itemhandle)));
END;
PROCEDURE SetDCtl (dlog : DialogPtr;
item : integer;
value : Boolean);
VAR
itemHandle : Handle;
itemType : integer;
itemRect : Rect;
BEGIN
GetDItem(dlog, item, itemType, itemHandle, itemRect);
SetCtlValue(ControlHandle(itemHandle), integer(value));
END;
PROCEDURE GetDtext (dlog : DialogPtr;
item : integer;
VAR str : Str255);
VAR
itemHandle : Handle;
itemType : integer;
itemRect : Rect;
BEGIN
GetDItem(dlog, item, itemType, itemHandle, itemRect);
GetIText(itemHandle, str);
END;
PROCEDURE SetDText (dlog : DialogPtr;
item : integer;
str : Str255);
VAR
itemHandle : Handle;
itemType : integer;
itemRect : Rect;
BEGIN
GetDItem(dlog, item, itemType, itemHandle, itemRect);
SetIText(itemHandle, str);
END;
PROCEDURE SetDProc (dlog : DialogPtr;
item : integer;
p : ProcPtr);
VAR
itemHandle : Handle;
itemType : integer;
itemRect : Rect;
BEGIN
GetDItem(dlog, item, itemType, itemHandle, itemRect);
SetDITem(dlog, item, itemType, Handle(p), itemRect);
END;
PROCEDURE SetDRadio (dlog : DialogPtr;
item : integer);
VAR
partner : DialogPtr;
itemHandle : Handle;
itemType : integer;
itemRect : Rect;
BEGIN
partner := DialogPtr(GetWRefCon(dlog));
SetDCtl(dlog, radio1, item = radio1);
SetDCtl(dlog, radio2, item = radio2);
SetDCtl(dlog, radio3, item = radio3);
IF partner = mDlog1 THEN
iconNum1 := item - radio1
ELSE
iconNum2 := item - radio1;
GetDItem(partner, user1, itemType, itemHandle, itemRect);
SetPort(partner);
InvalRect(itemRect);
END;
PROCEDURE Event (item : integer;
event : EventPtr);
VAR
actor, partner : DialogPtr;
title : Str255;
value : Boolean;
mypeek : WindowPeek;
mychar : Boolean;
BEGIN
GetPort(actor);
partner := DialogPtr(GetWRefCon(actor));
CASE item OF
button1 :
BEGIN
GetDText(actor, edit1, title);
SetWTitle(partner, title);
END;
radio1 :
SetDRadio(actor, radio1);
radio2 :
SetDRadio(actor, radio2);
radio3 :
SetDRadio(actor, radio3);
check1 :
BEGIN
value := NOT (GetDCtl(actor, item));
SetDCtl(actor, item, value);
IF value = false THEN
HideWindow(partner)
ELSE
ShowWindow(partner);
END;
check2 :
BEGIN
value := NOT (GetDCtl(actor, check2));
SetDCtl(actor, check2, value);
mypeek := WindowPeek(partner);
IF value THEN
mychar := true
ELSE
mychar := false;
mypeek^.goAwayFlag := mychar;
END;
OTHERWISE
END;
END;
PROCEDURE Close;
VAR
actor, partner : DialogPtr;
BEGIN
GetPort(actor);
partner := DialogPtr(GetWRefCon(actor));
HideWindow(actor);
SetDCtl(partner, check1, false);
END;
PROCEDURE Clobber;
VAR
theDialog : DialogPtr;
BEGIN
GetPort(theDialog);
DisposDialog(theDialog);
END;
{ File menu handler}
PROCEDURE DoFileMenu (item : integer);
BEGIN
CASE item OF
showDlog1 :
BEGIN
SelectWindow(mDlog1);
ShowWindow(mDlog1);
SetDCtl(mDlog2, check1, true);
END;
showDlog2 :
BEGIN
SelectWindow(mDlog2);
ShowWindow(mDlog2);
SetDCtl(mDlog1, check1, true);
END;
quit :
SkelWhoa;
END;
END;
{ Handle Edit menu items for text window}
PROCEDURE DoEditMenu (item : integer);
VAR
theDialog : DialogPtr;
mypeek : WindowPeek;
ignore : integer;
BEGIN
theDialog := DialogPtr(FrontWindow);
mypeek := WindowPeek(theDialog);
IF mypeek^.windowKind = dialogKind THEN
CASE item OF
cut :
BEGIN
DlgCut(theDialog);
ignore := ZeroScrap;
ignore := TEToScrap;
END;
copy :
BEGIN
DlgCopy(theDialog);
ignore := ZeroScrap;
ignore := TEToScrap;
END;
paste :
BEGIN
ignore := TEFromScrap;
DlgPaste(theDialog);
END;
clear :
DlgDelete(theDialog);
END;
END;
{ Handle selection of About… item from Apple menu}
PROCEDURE DoAbout;
VAR
ignore : integer;
BEGIN
ignore := Alert(aboutAlrtRes, NIL);
END;
FUNCTION DemoDialog (title : Str255;
x, y : integer) : DialogPtr;
VAR
theDialog : DialogPtr;
BEGIN
theDialog := GetNewDialog(mDlogRes, NIL, WindowPtr(-1));
MoveWindow(theDialog, x, y, false);
SetWTitle(theDialog, title);
SkelDialog(theDialog, @Event, @Close, @Clobber);
DemoDialog := theDialog;
END;
VAR
m : MenuHandle;
BEGIN
iconNum1 := 0;
iconNum2 := 0;
SkelInit;
SkelApple('AboutDialogSkel...', @DoAbout);
m := NewMenu(1000, 'File');
AppendMenu(m, 'Show Dialog 1;Show Dialog 2;(-;Quit/Q');
SkelMenu(m, @DoFileMenu, NIL);
m := NewMenu(1001, 'Edit');
AppendMenu(m, '(Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear');
SkelMenu(m, @DoEditMenu, NIL);
mDlog1 := DemoDialog('Modeless Dialog 1', 50, 50);
mDlog2 := DemoDialog('Modeless Dialog 2', 150, 200);
SetWRefCon(WindowPtr(mDlog1), longint(mDlog2));
SetWRefCon(WindowPtr(mDlog2), longint(mDlog1));
SetDText(mDlog1, edit1, 'Modeless Dialog 2');
SetDText(mDlog2, edit1, 'Modeless Dialog 1');
SetDProc(mDlog1, user1, @DrawIcon);
SetDProc(mDlog2, user1, @DrawIcon);
SetDCtl(mDlog1, radio1, true);
SetDCtl(mDlog2, radio1, true);
SetDCtl(mDlog1, check1, true);
SetDCtl(mDlog2, check1, true);
SetDCtl(mDlog1, check2, true);
SetDCtl(mDlog2, check2, true);
ShowWindow(mDlog1);
ShowWindow(mDlog2);
SkelMain;
SkelClobber;
END.